<?php 
	include "includes/conectionMySql.inc";
	
	$aux = 0;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Check List</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/vader/jquery-ui.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.10.3.custom.js"></script>
<script src="js/jquery.jqGrid.src.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-pt-br.js" type="text/javascript"></script>
<script type="text/javascript">
	function populaQtd(elemento){
		var min = 0, max = 100, select = document.getElementById(elemento);
		for(var i = min;i<=max;i++){
			var opt = document.createElement("option");
			opt.value = i;
			if(i==0){
				opt.innerHTML = "Todos";
			}else{
				opt.innerHTML = i;
			}
			if(i==<?php echo(isset($_GET['slctQtd']))?$_GET['slctQtd']:0?>){
				opt.setAttribute('selected','selected');
			}
			select.appendChild(opt);
		}
	}
	
	$(function(){
		jQuery('#list1').jqGrid({
			url:"listChecklist.php?slctQtd=<?php echo $_GET['slctQtd']?>&slctRota=<?php echo $_GET['slctRota']?>",
			datatype:'json',
			mtype: 'GET',
			colNames:['Nome','Estado','Cidade','Bairro','Rota','Telefones'],
			colModel:[
				{name:'nome',index:'nome',width:250,formatter:'showlink',formatoptions:{baseLinkUrl:'roteiroFuncionario.php'}},
				{name:'estado',index:'estado',width:120},
				{name:'cidade',index:'cidade',width:120},
				{name:'bairro',index:'bairro',width:120},
				{name:'rota',index:'rota',width:140},
				{name:'telefones',index:'telefones',width:120}
			],
			pager: '#pager1',
			sortname:'id',
			viewrecords: true,
			sortorder:"asc",
			caption:"Lista de Roteiros"
		});	
	});
</script>
</head>

<body>

<h3>Check list</h3>

<form action="formChecklist.php" method="get">

<table border="0">
<tr>
	<td>Quantidade:</td>
	<td><select id="slctQtd" name="slctQtd"></select></td>
</tr>
<tr>
	<td>Rota:</td>
    <td><select id="slctRota" name="slctRota">
    	<?php 
			$query = "SELECT a.id as id, a.nome as nome FROM rotas a WHERE aparecer = 1 order by nome asc";
			
			$result = mysql_query($query);
			while($linha = mysql_fetch_array($result,MYSQL_ASSOC)){
				?><option value="<?php echo $linha['id']?>"<?php echo ($_GET['slctRota']==$linha['id'])?' selected="selected" ':''; ?>><?php echo $linha['nome']?></option><?php
			}			
		?>
    	</select></td>
</tr>
<tr>
	<td></td>
    <td><input type="submit" value="Buscar"/>*</td>
</tr>
</table>
</form>
<br />
<table id="list1" name="list1"></table>
<div id="pager1" name="pager1"></div>
<p align="center"><a href="index.php">Voltar para menu inicial</a></p>
<br />
<p>* Para Testes utilizar os seguintes funcionários:<br />
Rota SÃO PAULO - Centro/ABC:
<ul>
	<li>Ana Maria Borges da Motta</li>
    <li>Cibelle Rodrigues Fernandes</li>
    <li>Desiree Suellen de Almeida</li>
</ul>
Rota SÃO PAULO - Leste:
<ul>
	<li>Cristina Santos da Conceição</li>
    <li>raul</li>
</ul>
</p>
<?php 
	mysql_close($db);
?>
<script type="text/javascript">
	populaQtd("slctQtd");
</script>
</body>
</html>